<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/popper.min.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <title>sjg mylog</title>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark" id="mynav">
</nav>
<div class="modal fade" id="logshow">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">logs</h4>
            </div>
            <div class="modal-body">
                <pre id="logs_result" style="white-space: pre-wrap;word-wrap: break-word;"></pre>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">close</button>
            </div>
        </div>
    </div>
</div>

<div class="container-fluid">
    <div class="row">
        <div class="col">
            <br />
            <form class="form-inline">
                <input type="text" class="form-control" id="text_search">
                <button type="button" class="btn" id="bt_search">search</button>
            </form>
            <table class="table table-bordered table-hover">
                <thead>
                <th>id</th>
                <th>name</th>
                <th>logpath</th>
                <th>proxy</th>
                <th>writeresult</th>
                <th>operation</th>
                </thead>
                <tbody id="content">

                </tbody>
            </table>
            <p id="pageinfo"></p>
        </div>
    </div>
</div>
<script src="/static/js/thesame.js"></script>
<script type="text/javascript">
        function get_page(pagenow, pagesize, search) {
        info = { "pagenow": pagenow, "pagesize": pagesize, "search": search }
        allpage = 0
        myajax = $.ajax({
            url: '/action_mylog/get_by_page/',
            type: 'post',
            cache: false,
            data: JSON.stringify(info),
            success: function (data) {
                tmpresult = JSON.parse(data);
                allresult = tmpresult['result'];
                allcount = tmpresult['allcount'];
                allpage = Math.ceil(allcount/pagesize);
                $("#content").html("");
                for (i = 0; i < allresult.length; i++) {
                    fields = allresult[i]['fields']
                    tmpone = '<tr>'
                    tmpone = tmpone + '<td>' + allresult[i]['pk'] + '</td>'
                    tmpone = tmpone + '<td>' + fields['name'] + '</td>'
                    tmpone = tmpone + '<td>' + fields['logpath'] + '</td>'
                    tmpone = tmpone + '<td>' + fields['proxy'] + '</td>'
                    tmpone = tmpone + '<td>' + fields['writeresult'] + '</td>'
                    tmpone = tmpone + '<td>'
                    tmpone = tmpone + '<button class="btn btn-sm" onClick="chakan(' + allresult[i]['pk'] + ')">查看</button>  '
                    tmpone = tmpone + '<button class="btn btn-sm" onClick="openupdate(' + allresult[i]['pk'] + ')">update</button>'
                    tmpone = tmpone + '</td>'
                    tmpone = tmpone + '</tr>'
                    $("#content").append(tmpone);
                }
                pagedown = `<button id="pagedown" type='button' onclick="get_page(${pagenow-1},${pagesize}, '${search}')" class='btn btn-sm'>上一页</button>`;
                pageup = `<button id="pageup" type='button' onclick="get_page(${pagenow+1},${pagesize}, '${search}')" class='btn btn-sm'>下一页</button>`;
                $("#pageinfo").html(`当前页：<p style='display: inline;' id='pagenow'>${pagenow}</p>, 每页条数: ${pagesize}, 总页数：${allpage}, 总条数：${allcount}`);
                $("#pageinfo").append(" "+pagedown);
                $("#pageinfo").append(" "+pageup);
                if(pagenow == 1){ $('#pagedown').addClass('disabled');$('#pagedown').removeAttr("onclick"); }
                if(pagenow == allpage){ $('#pageup').addClass('disabled');$('#pageup').removeAttr("onclick"); }
            }
        });
    }
    function openupdate(id) {
        window.open("/admin/sjgapp/mylog/"+id);
    }

    function chakan(id){
        window.open("/static/mylogdetail.html?id="+id);
    }

    $(document).ready(function () {
        get_page(1, 15, '');
        $('#bt_search').click(function () {
            text_search = $('#text_search').val();
            get_page(1,15,text_search)
        });
    });
</script>

</body>
</html>